package com.cy.common;

import lombok.Data;

/**
 * 响应结果类1
 * @param <T>
 */
@Data
public class ResultResponse<T> {
    private String code;
    private String Msg;
    private T data;
    private int count;

    public String getCode() {
        return code;
    }

    /**
     * 通过在每个设置方法中返回 this，可以在设置一个参数后继续链式调用其他方法，
     * 而不必每次都手动引用对象。这种技术通常被称为"fluent interface"或"method chaining"。
     * @param code
     * @return
     */
    public ResultResponse setCode(String code) {
        this.code = code;
        return this;
    }

    public String Msg() {
        return Msg;
    }

    public ResultResponse setMsg(String Msg) {
        this.Msg = Msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public ResultResponse setData(T data) {
        this.data = data;
        return this;
    }

    public int getCount() {
        return count;
    }

    public ResultResponse setCount(int count) {
        this.count = count;
        return this;
    }

    /**
     * 成功
     * @return
     * @param <T>
     */
    public static <T> ResultResponse success(){
        return new ResultResponse().setCode(ResponseEnum.SUCCESS.getCode()).
                setMsg(ResponseEnum.SUCCESS.getMsg()).
                setData("");
    }
    public static <T> ResultResponse success(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.SUCCESS.getCode()).
                setMsg(ResponseEnum.SUCCESS.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse success(T data){
        return new ResultResponse().setCode(ResponseEnum.SUCCESS.getCode()).
                setMsg(ResponseEnum.SUCCESS.getMsg()).
                setData(data);
    }
    public static <T> ResultResponse success(int count){
        return new ResultResponse().setCode(ResponseEnum.SUCCESS.getCode()).
                setMsg(ResponseEnum.SUCCESS.getMsg()).setCount(count);
    }
    public static <T> ResultResponse success(String Msg){
        return new ResultResponse().setCode(ResponseEnum.SUCCESS.getCode()).
                setMsg(Msg);
    }

    /**
     * 失败
     * @return
     * @param <T>
     */
    public static <T> ResultResponse fail(){
        return new ResultResponse().setCode(ResponseEnum.FAIL.getCode()).
                setMsg(ResponseEnum.FAIL.getMsg()).
                setData("");
    }
    public static <T> ResultResponse fail(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.FAIL.getCode()).
                setMsg(ResponseEnum.FAIL.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse fail(int count){
        return new ResultResponse().setCode(ResponseEnum.FAIL.getCode()).
                setMsg(ResponseEnum.FAIL.getMsg()).setCount(count);
    }
    public static <T> ResultResponse fail(String Msg){
        return new ResultResponse().setCode(ResponseEnum.FAIL.getCode()).
                setMsg(Msg);
    }

    /**
     * 无相关信息
     * @return
     * @param <T>
     */
    public static <T> ResultResponse notFound(){
        return new ResultResponse().setCode(ResponseEnum.NOTFOUND.getCode()).
                setMsg(ResponseEnum.NOTFOUND.getMsg()).
                setData("");
    }
    public static <T> ResultResponse notFound(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.NOTFOUND.getCode()).
                setMsg(ResponseEnum.NOTFOUND.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse notFound(int count){
        return new ResultResponse().setCode(ResponseEnum.NOTFOUND.getCode()).
                setMsg(ResponseEnum.NOTFOUND.getMsg()).setCount(count);
    }
    public static <T> ResultResponse notFound(String Msg){
        return new ResultResponse().setCode(ResponseEnum.NOTFOUND.getCode()).
                setMsg(Msg);
    }

    /**
     * 该信息已存在
     * @return
     * @param <T>
     */
    public static <T> ResultResponse exist(){
        return new ResultResponse().setCode(ResponseEnum.EXIST.getCode()).
                setMsg(ResponseEnum.EXIST.getMsg()).
                setData("");
    }
    public static <T> ResultResponse exist(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.EXIST.getCode()).
                setMsg(ResponseEnum.EXIST.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse exist(int count){
        return new ResultResponse().setCode(ResponseEnum.EXIST.getCode()).
                setMsg(ResponseEnum.EXIST.getMsg()).setCount(count);
    }
    public static <T> ResultResponse exist(String Msg){
        return new ResultResponse().setCode(ResponseEnum.EXIST.getCode()).
                setMsg(Msg);
    }
    /**
     * 参数错误
     * @return
     * @param <T>
     */
    public static <T> ResultResponse error(){
        return new ResultResponse().setCode(ResponseEnum.ERROR.getCode()).
                setMsg(ResponseEnum.ERROR.getMsg()).
                setData("");
    }
    public static <T> ResultResponse error(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.ERROR.getCode()).
                setMsg(ResponseEnum.ERROR.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse error(int count){
        return new ResultResponse().setCode(ResponseEnum.ERROR.getCode()).
                setMsg(ResponseEnum.ERROR.getMsg()).setCount(count);
    }
    public static <T> ResultResponse error(String Msg){
        return new ResultResponse().setCode(ResponseEnum.ERROR.getCode()).
                setMsg(Msg);
    }
    /**
     * 密码错误
     * @return
     * @param <T>
     */
    public static <T> ResultResponse pwderror(){
        return new ResultResponse().setCode(ResponseEnum.PWDERROR.getCode()).
                setMsg(ResponseEnum.PWDERROR.getMsg()).
                setData("");
    }
    public static <T> ResultResponse pwderror(T data,int count){
        return new ResultResponse().setCode(ResponseEnum.PWDERROR.getCode()).
                setMsg(ResponseEnum.PWDERROR.getMsg()).
                setData(data).setCount(count);
    }
    public static <T> ResultResponse pwderror(int count){
        return new ResultResponse().setCode(ResponseEnum.PWDERROR.getCode()).
                setMsg(ResponseEnum.PWDERROR.getMsg()).setCount(count);
    }
    public static <T> ResultResponse pwderror(String Msg){
        return new ResultResponse().setCode(ResponseEnum.PWDERROR.getCode()).
                setMsg(Msg);
    }

    public ResultResponse() {
    }

    public ResultResponse(String code, String Msg, T data, int count) {
        this.code = code;
        this.Msg = Msg;
        this.data = data;
        this.count = count;
    }

    @Override
    public String toString() {
        return "ResultResponse{" +
                "code='" + code + '\'' +
                ", Msg='" + Msg + '\'' +
                ", data=" + data +
                ", count=" + count +
                '}';
    }
}
